// pages/mycard/mycard.js
const app = getApp();
var router = require("../../router.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[      
    ],
    page: 0
  },
  go_card_detail(e){
    let cardid = e.currentTarget.dataset.cardid;
    wx.navigateTo({
      url: './card_detail/card_detail?id='+cardid,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.get_info();
  },
  
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.get_info();
  },

  get_info: function(){
    var that = this;
    app.request({
      url: router.user.coupon,
      method: "POST",
      data: {
        userId: wx.getStorageSync('userInfo').id,
        page: that.data.page
      },
      success: function (data) {
        console.log(data);
        if (data.status == true) {
          if (data.coupon.length > 0) {
            for (var i = 0; i < data.coupon.length; i++) {
              var obj = {};
              data.coupon[i].bg_pic = '../../image/c2.jpg';
              obj = data.coupon[i];
              that.data.list.push(obj);
            }
            that.setData({
              list: that.data.list,
              page: that.data.page + 1
            });
          }
        } else {
          wx.showToast({
            title: '获取信息失败',
            icon: 'none',
            mask: true,
            duration: 2000
          });
        }
      }
    })
  }
})